# Maintainer: Dylan Van Assche <me@dylanvanassche.be>
# Contributor: Dylan Van Assche <me@dylanvanassche.be>
pkgname=solid-community-server
pkgver=2.0.1
pkgrel=1
pkgdesc="An open and modular implementation of the Solid specifications"
url="https://github.com/solid/community-server"
arch="all !x86 !armhf !riscv64" # x86 textrels, armhf failing tests, riscv64 nodejs missing
license="MIT"
depends="nodejs>=12"
makedepends="npm build-base python3"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="$pkgname-$pkgver-2.tar.gz::https://github.com/solid/community-server/archive/refs/tags/v$pkgver.tar.gz
	solid-community-server.initd
	disable-husky.patch"
builddir="$srcdir/CommunitySolidServer-$pkgver"

build() {
	npm install --include=dev
	npm run build
}

check() {
	npm run test
}

package() {
	mkdir -p "$pkgdir"/usr/share/webapps/solid-community-server
	mkdir -p "$pkgdir"/usr/bin

	cp -r "$builddir"/package.json \
		"$builddir"/bin \
		"$builddir"/config \
		"$builddir"/dist \
		"$builddir"/node_modules \
		"$builddir"/templates \
		"$pkgdir"/usr/share/webapps/solid-community-server

	# Solid Community Server extensions expect the community server to be
	# in node_modules while this is not the case when installing
	# release tarballs.
	mkdir -p "$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server"
	ln -s "$pkgdir/usr/share/webapps/solid-community-server/bin" \
		"$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server/bin"
	ln -s "$pkgdir/usr/share/webapps/solid-community-server/config" \
		"$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server/config"
	ln -s "$pkgdir/usr/share/webapps/solid-community-server/dist" \
		"$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server/dist"
	ln -s "$pkgdir/usr/share/webapps/solid-community-server/templates" \
		"$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server/templates"
	ln -s "$pkgdir/usr/share/webapps/solid-community-server/package.json" \
		"$pkgdir/usr/share/webapps/solid-community-server/node_modules/@solid/community-server/package.json"

	ln -s /usr/share/webapps/solid-community-server/bin/server.js \
		"$pkgdir"/usr/bin/solid-community-server

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
c5419ee7df527e61e244ee375479118a8f008efbf9f2a067f8a9afdea916c226cb2d90b3d7357cc58ea3175f74873cf607da79996ff38cadbdf2e4f93820986a  solid-community-server-2.0.1-2.tar.gz
5d48353a2ee00411967dccbe37fa140134f734cf0f87fa04b489a05978b9a1e1ec8908ff003c5e25523345943672dde1eeb5e0b559d96407c67eb7f287601a53  solid-community-server.initd
d3866bbc93c6824df4786c5f57008933ffa373f4cb8a9c66836def88c52d8cc8b2b91d22f0631bec8363fe7209b8a829e438a1f26a7df66d9fdf4afc45ef59f2  disable-husky.patch
"
